home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / tex / rail.zip / LEX.C < prev    next >
C/C++ Source or Header  |  1992-01-15  |  11KB  |  577 lines

  1. # include "stdio.h"
  2. # define U(x) x
  3. # define NLSTATE yyprevious=YYNEWLINE
  4. # define BEGIN yybgin = yysvec + 1 +
  5. # define INITIAL 0
  6. # define YYLERR yysvec
  7. # define YYSTATE (yyestate-yysvec-1)
  8. # define YYOPTIM 1
  9. # define YYLMAX BUFSIZ
  10. # define output(c) putc(c,yyout)
  11. # define input() (((yytchar=yysptr>yysbuf?U(*--yysptr):getc(yyin))==10?(yylineno++,yytchar):yytchar)==EOF?0:yytchar)
  12. # define unput(c) {yytchar= (c);if(yytchar=='\n')yylineno--;*yysptr++=yytchar;}
  13. # define yymore() (yymorfg=1)
  14. # define ECHO fprintf(yyout, "%s",yytext)
  15. # define REJECT { nstr = yyreject(); goto yyfussy;}
  16. int yyleng; extern char yytext[];
  17. int yymorfg;
  18. extern char *yysptr, yysbuf[];
  19. int yytchar;
  20. FILE *yyin = {stdin}, *yyout = {stdout};
  21. extern int yylineno;
  22. struct yysvf { 
  23.     struct yywork *yystoff;
  24.     struct yysvf *yyother;
  25.     int *yystops;};
  26. struct yysvf *yyestate;
  27. extern struct yysvf yysvec[], *yybgin;
  28.  
  29. #include "rail.h"
  30. #include "gram.h"
  31.  
  32. int lex_line;    /* current input line */
  33. int copy;    /* copy to output flag */
  34.  
  35. #define    COPY    (copy && fputs(yytext,outf))
  36.  
  37. extern YYSTYPE yylval;
  38.  
  39. # define YYNEWLINE 10
  40. yylex(){
  41. int nstr; extern int yyprevious;
  42. while((nstr = yylook()) >= 0)
  43. yyfussy: switch(nstr){
  44. case 0:
  45. if(yywrap()) return(0); break;
  46. case 1:
  47. {
  48.         COPY;
  49.         yylval.id=lookup(yytext);
  50.         return(IDENTIFIER);
  51. }
  52. case 2:
  53. {
  54.         COPY;
  55.         yylval.num=atoi(yytext);
  56.         return(NUMBER);
  57. }
  58. case 3:
  59. {
  60.         COPY;
  61.         return(RAILI);
  62. }
  63. case 4:
  64. {
  65.         COPY;
  66.         return(RAILP);
  67. }
  68. case 5:
  69. {
  70.         COPY;
  71.         return(RAILT);
  72. }
  73. case 6:
  74.     COPY;
  75. break;
  76. case 7:
  77. {        COPY;
  78.         return(RAILCR);
  79. }
  80. case 8:
  81. {
  82.         COPY;
  83.         return(CS);
  84. }
  85. case 9:
  86. {
  87.         COPY;
  88.         return(CS);
  89. }
  90. case 10:
  91. {
  92.         COPY;
  93.         yytext[yyleng-1]='\0';
  94.         yylval.text=mcheck(strdup(yytext+1));
  95.         return(STRING);
  96. }
  97. case 11:
  98. {
  99.         COPY;
  100.         yytext[yyleng-1]='\0';
  101.         yylval.text=mcheck(strdup(yytext+1));
  102.         return(ANNOT);
  103. }
  104. case 12:
  105. {
  106.         COPY;
  107.         yytext[yyleng-1]='\0';
  108.         yylval.text=mcheck(strdup(yytext+1));
  109.         return(STRING);
  110. }
  111. case 13:
  112. {
  113.         COPY;
  114. }
  115. break;
  116. case 14:
  117. {
  118.         COPY;
  119.         lex_line++;
  120. }
  121. break;
  122. case 15:
  123. {
  124.         COPY;
  125.         return(yytext[0]);
  126. }
  127. case -1:
  128. break;
  129. default:
  130. fprintf(yyout,"bad switch yylook %d",nstr);
  131. } return(0); }
  132. /* end of yylex */
  133. int yyvstop[] = {
  134. 0,
  135.  
  136. 15,
  137. 0,
  138.  
  139. 13,
  140. 15,
  141. 0,
  142.  
  143. 14,
  144. 0,
  145.  
  146. 15,
  147. 0,
  148.  
  149. 15,
  150. 0,
  151.  
  152. 2,
  153. 15,
  154. 0,
  155.  
  156. 1,
  157. 15,
  158. 0,
  159.  
  160. 15,
  161. 0,
  162.  
  163. 15,
  164. 0,
  165.  
  166. 13,
  167. 0,
  168.  
  169. 12,
  170. 0,
  171.  
  172. 10,
  173. 0,
  174.  
  175. 2,
  176. 0,
  177.  
  178. 1,
  179. 0,
  180.  
  181. 11,
  182. 0,
  183.  
  184. 9,
  185. 0,
  186.  
  187. 8,
  188. 9,
  189. 0,
  190.  
  191. 7,
  192. 9,
  193. 0,
  194.  
  195. 8,
  196. 9,
  197. 0,
  198.  
  199. 8,
  200. 9,
  201. 0,
  202.  
  203. 8,
  204. 0,
  205.  
  206. 8,
  207. 0,
  208.  
  209. 8,
  210. 0,
  211.  
  212. 6,
  213. 8,
  214. 0,
  215.  
  216. 8,
  217. 0,
  218.  
  219. 8,
  220. 0,
  221.  
  222. 8,
  223. 0,
  224.  
  225. 3,
  226. 8,
  227. 0,
  228.  
  229. 4,
  230. 8,
  231. 0,
  232.  
  233. 5,
  234. 8,
  235. 0,
  236. 0};
  237. # define YYTYPE char
  238. struct yywork { YYTYPE verify, advance; } yycrank[] = {
  239. 0,0,    0,0,    1,3,    0,0,    
  240. 0,0,    0,0,    0,0,    0,0,    
  241. 6,13,    0,0,    1,4,    1,5,    
  242. 7,15,    4,12,    0,0,    0,0,    
  243. 6,0,    6,0,    0,0,    0,0,    
  244. 7,0,    7,0,    0,0,    0,0,    
  245. 0,0,    0,0,    0,0,    0,0,    
  246. 0,0,    0,0,    0,0,    0,0,    
  247. 0,0,    1,4,    0,0,    1,6,    
  248. 4,12,    13,0,    13,0,    6,13,    
  249. 1,7,    6,14,    0,0,    7,15,    
  250. 0,0,    7,15,    6,13,    1,3,    
  251. 0,0,    1,8,    7,16,    15,0,    
  252. 15,0,    6,13,    0,0,    6,13,    
  253. 0,0,    7,15,    0,0,    7,15,    
  254. 19,0,    19,0,    0,0,    0,0,    
  255. 0,0,    1,3,    1,9,    0,0,    
  256. 0,0,    0,0,    0,0,    6,13,    
  257. 6,13,    0,0,    0,0,    7,15,    
  258. 7,15,    8,17,    8,17,    8,17,    
  259. 8,17,    8,17,    8,17,    8,17,    
  260. 8,17,    8,17,    8,17,    0,0,    
  261. 0,0,    0,0,    31,32,    0,0,    
  262. 1,10,    1,11,    1,3,    0,0,    
  263. 1,9,    2,10,    2,11,    0,0,    
  264. 6,13,    0,0,    6,13,    0,0,    
  265. 7,15,    9,18,    7,15,    9,18,    
  266. 9,18,    9,18,    9,18,    9,18,    
  267. 9,18,    9,18,    9,18,    9,18,    
  268. 9,18,    0,0,    0,0,    0,0,    
  269. 24,27,    25,28,    0,0,    0,0,    
  270. 9,18,    9,18,    9,18,    9,18,    
  271. 9,18,    9,18,    9,18,    9,18,    
  272. 9,18,    9,18,    9,18,    9,18,    
  273. 9,18,    9,18,    9,18,    9,18,    
  274. 9,18,    9,18,    9,18,    9,18,    
  275. 9,18,    9,18,    9,18,    9,18,    
  276. 9,18,    9,18,    27,29,    28,30,    
  277. 30,31,    0,0,    9,18,    0,0,    
  278. 9,18,    9,18,    9,18,    9,18,    
  279. 9,18,    9,18,    9,18,    9,18,    
  280. 9,18,    9,18,    9,18,    9,18,    
  281. 9,18,    9,18,    9,18,    9,18,    
  282. 9,18,    9,18,    9,18,    9,18,    
  283. 9,18,    9,18,    9,18,    9,18,    
  284. 9,18,    9,18,    10,19,    0,0,    
  285. 0,0,    32,33,    11,21,    0,0,    
  286. 0,0,    0,0,    10,0,    10,0,    
  287. 32,34,    0,0,    11,0,    11,0,    
  288. 32,35,    0,0,    0,0,    0,0,    
  289. 0,0,    0,0,    0,0,    0,0,    
  290. 0,0,    0,0,    0,0,    0,0,    
  291. 0,0,    0,0,    0,0,    0,0,    
  292. 0,0,    10,19,    0,0,    10,19,    
  293. 0,0,    11,0,    0,0,    11,21,    
  294. 10,19,    0,0,    0,0,    0,0,    
  295. 11,21,    0,0,    0,0,    10,19,    
  296. 0,0,    10,19,    0,0,    11,21,    
  297. 0,0,    11,21,    0,0,    0,0,    
  298. 0,0,    0,0,    0,0,    0,0,    
  299. 0,0,    0,0,    0,0,    0,0,    
  300. 0,0,    10,19,    10,19,    0,0,    
  301. 0,0,    11,22,    11,22,    0,0,    
  302. 0,0,    0,0,    0,0,    0,0,    
  303. 0,0,    0,0,    0,0,    0,0,    
  304. 0,0,    0,0,    0,0,    0,0,    
  305. 0,0,    0,0,    0,0,    0,0,    
  306. 0,0,    0,0,    0,0,    0,0,    
  307. 0,0,    0,0,    10,20,    0,0,    
  308. 10,19,    11,23,    11,21,    0,0,    
  309. 11,21,    0,0,    0,0,    0,0,    
  310. 0,0,    0,0,    0,0,    0,0,    
  311. 0,0,    0,0,    0,0,    0,0,    
  312. 0,0,    0,0,    0,0,    0,0,    
  313. 0,0,    11,24,    0,0,    11,25,    
  314. 22,26,    22,26,    22,26,    22,26,    
  315. 22,26,    22,26,    22,26,    22,26,    
  316. 22,26,    22,26,    22,26,    22,26,    
  317. 22,26,    22,26,    22,26,    22,26,    
  318. 22,26,    22,26,    22,26,    22,26,    
  319. 22,26,    22,26,    22,26,    22,26,    
  320. 22,26,    22,26,    22,26,    0,0,    
  321. 0,0,    0,0,    0,0,    0,0,    
  322. 0,0,    22,26,    22,26,    22,26,    
  323. 22,26,    22,26,    22,26,    22,26,    
  324. 22,26,    22,26,    22,26,    22,26,    
  325. 22,26,    22,26,    22,26,    22,26,    
  326. 22,26,    22,26,    22,26,    22,26,    
  327. 22,26,    22,26,    22,26,    22,26,    
  328. 22,26,    22,26,    22,26,    0,0,    
  329. 0,0};
  330. struct yysvf yysvec[] = {
  331. 0,    0,    0,
  332. yycrank+-1,    0,        0,    
  333. yycrank+-6,    yysvec+1,    0,    
  334. yycrank+0,    0,        yyvstop+1,
  335. yycrank+4,    0,        yyvstop+3,
  336. yycrank+0,    0,        yyvstop+6,
  337. yycrank+-7,    0,        yyvstop+8,
  338. yycrank+-11,    0,        yyvstop+10,
  339. yycrank+29,    0,        yyvstop+12,
  340. yycrank+59,    0,        yyvstop+15,
  341. yycrank+-181,    0,        yyvstop+18,
  342. yycrank+-185,    0,        yyvstop+20,
  343. yycrank+0,    yysvec+4,    yyvstop+22,
  344. yycrank+-28,    yysvec+6,    0,    
  345. yycrank+0,    0,        yyvstop+24,
  346. yycrank+-42,    yysvec+7,    0,    
  347. yycrank+0,    0,        yyvstop+26,
  348. yycrank+0,    yysvec+8,    yyvstop+28,
  349. yycrank+0,    yysvec+9,    yyvstop+30,
  350. yycrank+-51,    yysvec+10,    0,    
  351. yycrank+0,    0,        yyvstop+32,
  352. yycrank+0,    0,        yyvstop+34,
  353. yycrank+236,    0,        yyvstop+36,
  354. yycrank+0,    0,        yyvstop+39,
  355. yycrank+23,    yysvec+22,    yyvstop+42,
  356. yycrank+24,    yysvec+22,    yyvstop+45,
  357. yycrank+0,    yysvec+22,    yyvstop+48,
  358. yycrank+36,    yysvec+22,    yyvstop+50,
  359. yycrank+46,    yysvec+22,    yyvstop+52,
  360. yycrank+0,    yysvec+22,    yyvstop+54,
  361. yycrank+44,    yysvec+22,    yyvstop+57,
  362. yycrank+26,    yysvec+22,    yyvstop+59,
  363. yycrank+80,    yysvec+22,    yyvstop+61,
  364. yycrank+0,    yysvec+22,    yyvstop+63,
  365. yycrank+0,    yysvec+22,    yyvstop+66,
  366. yycrank+0,    yysvec+22,    yyvstop+69,
  367. 0,    0,    0};
  368. struct yywork *yytop = yycrank+358;
  369. struct yysvf *yybgin = yysvec+1;
  370. char yymatch[] = {
  371. 00  ,01  ,01  ,01  ,01  ,01  ,01  ,01  ,
  372. 01  ,011 ,012 ,01  ,01  ,01  ,01  ,01  ,
  373. 01  ,01  ,01  ,01  ,01  ,01  ,01  ,01  ,
  374. 01  ,01  ,01  ,01  ,01  ,01  ,01  ,01  ,
  375. 040 ,01  ,'"' ,01  ,01  ,01  ,01  ,047 ,
  376. 01  ,01  ,01  ,01  ,01  ,01  ,'.' ,01  ,
  377. '0' ,'0' ,'0' ,'0' ,'0' ,'0' ,'0' ,'0' ,
  378. '0' ,'0' ,01  ,01  ,01  ,01  ,01  ,01  ,
  379. '@' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,
  380. 'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,
  381. 'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,
  382. 'A' ,'A' ,'A' ,01  ,01  ,']' ,01  ,'_' ,
  383. 01  ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,
  384. 'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,
  385. 'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,
  386. 'A' ,'A' ,'A' ,01  ,01  ,01  ,01  ,01  ,
  387. 0};
  388. char yyextra[] = {
  389. 0,0,0,0,0,0,0,0,
  390. 0,0,0,0,0,0,0,0,
  391. 0};
  392. #ifndef lint
  393. static    char ncform_sccsid[] = "@(#)ncform 1.6 88/02/08 SMI"; /* from S5R2 1.2 */
  394. #endif
  395.  
  396. int yylineno =1;
  397. # define YYU(x) x
  398. # define NLSTATE yyprevious=YYNEWLINE
  399. char yytext[YYLMAX];
  400. struct yysvf *yylstate [YYLMAX], **yylsp, **yyolsp;
  401. char yysbuf[YYLMAX];
  402. char *yysptr = yysbuf;
  403. int *yyfnd;
  404. extern struct yysvf *yyestate;
  405. int yyprevious = YYNEWLINE;
  406. yylook(){
  407.     register struct yysvf *yystate, **lsp;
  408.     register struct yywork *yyt;
  409.     struct yysvf *yyz;
  410.     int yych, yyfirst;
  411.     struct yywork *yyr;
  412. # ifdef LEXDEBUG
  413.     int debug;
  414. # endif
  415.     char *yylastch;
  416.     /* start off machines */
  417. # ifdef LEXDEBUG
  418.     debug = 0;
  419. # endif
  420.     yyfirst=1;
  421.     if (!yymorfg)
  422.         yylastch = yytext;
  423.     else {
  424.         yymorfg=0;
  425.         yylastch = yytext+yyleng;
  426.         }
  427.     for(;;){
  428.         lsp = yylstate;
  429.         yyestate = yystate = yybgin;
  430.         if (yyprevious==YYNEWLINE) yystate++;
  431.         for (;;){
  432. # ifdef LEXDEBUG
  433.             if(debug)fprintf(yyout,"state %d\n",yystate-yysvec-1);
  434. # endif
  435.             yyt = yystate->yystoff;
  436.             if(yyt == yycrank && !yyfirst){  /* may not be any transitions */
  437.                 yyz = yystate->yyother;
  438.                 if(yyz == 0)break;
  439.                 if(yyz->yystoff == yycrank)break;
  440.                 }
  441.             *yylastch++ = yych = input();
  442.             yyfirst=0;
  443.         tryagain:
  444. # ifdef LEXDEBUG
  445.             if